package com.controller;

import com.DAO.UsuarioDAO;
import com.model.Usuario;
import com.util.HibernateUtil;
import com.util.Session;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.view.componet.Header;
import com.view.componet.Menu;

public class GerenciadorDespesasController {

	private Window mainWindow;
	private VerticalLayout main;
	private LoginController loginController;
	public GerenciadorDespesasController(Window  mainWindow, VerticalLayout main){
		
	   this.mainWindow = mainWindow;	
	   this.main = main;	
       
	   HibernateUtil.openSession();
	   
	   	Usuario u = new Usuario();
		u.setCpf( 11111111111l);
		u.setSenha("102030");
		u.setNome("Victor");
		
		org.hibernate.Session s = HibernateUtil.openSession();
		UsuarioDAO usuarioDAO = new UsuarioDAO(s, Usuario.class);
	   	s.beginTransaction().begin();
	 	usuarioDAO.save(u);
	   	s.beginTransaction().commit();
	    s.close();
	    login();
	}
	
	public void login(){
	   main.removeAllComponents();
	   loginController = new LoginController();
	   loginController.setGerenciadorDespesas(this);
	   mainWindow.addWindow(loginController.getView());
		
	}
	
	public void init(){
		 
		
		if(Session.getInstance() != null){
			   main.setSizeFull();
	     	   Header header = new Header(loginController);
	           main.addComponent(header);
	           Menu menu = new Menu();
	           main.addComponent(menu);
	           main.setExpandRatio(menu,1 );
	       }
		
	}

	public Window getMainWindow() {
		return mainWindow;
	}

	public void setMainWindow(Window mainWindow) {
		this.mainWindow = mainWindow;
	}

	public VerticalLayout getMain() {
		return main;
	}

	public void setMain(VerticalLayout main) {
		this.main = main;
	}
	
	
	
}
